// 下拉菜单
function Tab(){
    this.cate=document.querySelector(".cate");
    this.ali=document.querySelectorAll(".cateList li");
    this.sub = document.querySelector(".subList")
    this.adiv=document.querySelectorAll(".subList>.bd");
    this.h3_red=document.querySelectorAll(".cateList h3")
    this.index=0;
    this.addEvent()
}
Tab.prototype.addEvent=function(){
    const that = this;
    for(let i=0;i<this.ali.length;i++){
        this.ali[i].xuhao = i;
        this.ali[i].onmouseenter = function(){
            that.hide()
            that.getIndex(this)
            that.show()
        }
    }
    this.cate.onmouseenter=function(){
        that.sub.style.display="block"
    }
    this.cate.onmouseleave=function(){
        that.sub.onmouseenter=function(){
            that.show()
        }
        that.sub.onmouseleave=function(){
            that.hide()
        }
        that.hide()
    }
}
Tab.prototype.hide=function(){
    this.sub.style.display="none"
    this.ali[this.index].style.background="#fafafa"
    this.adiv[this.index].style.display="none"
    this.adiv[this.index].style.opacity = "0";
}
Tab.prototype.show = function(){
    this.sub.style.display="block"
    this.ali[this.index].style.background = "#f2f2f2";
    this.adiv[this.index].style.display = "block";
    this.adiv[this.index].style.opacity = "1";
}
Tab.prototype.getIndex = function(now){
    this.index = now.xuhao;
}
new Tab();
